package com.intct.flink;

import com.intct.hbase.bean.Student;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author gufg
 * @since 2025-06-27 09:26
 */
public class UnionDemo {
    public static void main(String[] args) throws Exception {
        // 创建环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        /**
         * Union是多个数流之间的字段和数据类型必须要一致
         */

        // 数据源 1
        DataStreamSource<Student> stuDS1 = env.fromElements(
                new Student("c01", "s01", 88L),
                new Student("c01", "s02", 77L),
                new Student("c01", "s03", 66L)
        );

        // 数据源 2
        DataStreamSource<Student> stuDS2 = env.fromElements(
                new Student("c01", "s01", 88L),
                new Student("c01", "s02", 3L),
                new Student("c03", "s05", 4L)
        );

        // Union操作
        stuDS1.union(stuDS2).print();

        // 输出

        // 启动作业
        env.execute();
    }
}
